import com.sun.xml.internal.ws.addressing.WsaActionUtil;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2024-04-01
 * Time: 8:28
 */
public enum EnumTest {
    RED("red",1),GREEN("green" ,2) ,BLACK("blkack",3);
    public String color;
    public int ordinal;

    private  EnumTest(String color,int ordinal){
        this.color=color;
        this.ordinal=ordinal;
    }

    public static void main(String[] args) {
        EnumTest enumTest=EnumTest.valueOf("GREEN");
        /**
         *     EnumTest.valueof()将字符串转变成枚举实例,若枚举实例中没有,则会抛异常
         */
        System.out.println(enumTest);
        /**
         * compareTo(),比较两个枚举对象在定义时的顺序
         */
        System.out.println(RED.compareTo(GREEN));
    }

    public static void main2(String[] args) {
        /**
         * EnumTest.values(),以数组形式返回枚举类型的全部成员
         */
        EnumTest[] enumTest=EnumTest.values();
        for (int i = 0; i < enumTest.length ; i++) {
            System.out.println(enumTest[i]+" " +enumTest[i].ordinal());
            /**
             * enumTest[i].ordinal(),获得枚举成员的索引位置
             */

        }

    }

    public static void main1(String[] args) {
        EnumTest enumTest=EnumTest.RED;
        switch (enumTest){
            case RED:
                System.out.println("dhhedg");
                break;
            case BLACK:
                break;
            case GREEN:
                break;
            default:
                break;
        }

    }
}
